package edu.neumont.pro180._2009_q2.chess;

import java.awt.Point;
import java.util.Collection;
import java.util.HashSet;

import edu.neumont.pro180._2009_q2.GamePiece;
import edu.neumont.pro180._2009_q2.Square;

public class Knight extends GamePiece {
	private final int value = 3;
	
	@Override
	public int getValue() {
		return value;
	}
	
	private static Point[] moveOffsets = new Point[]{
		new Point(2,1),
		new Point(2,-1),
		new Point(1,2),
		new Point(-1,2),
		new Point(-2,1),
		new Point(-2,-1),
		new Point(1,-2),
		new Point(-1,-2)
	};
	@Override
	public Collection<Square> getPossibleSquares() {
		Collection<Square> moves = new HashSet<Square>();
		for (Point moveOffset : moveOffsets) {
			Square move;
			
			// Assign the move to be the neighbor, and check to see if the
			// result was null. A bit tricky to look at if you're not used to it.
			if (null != (move = this.getPosition().getNeighbor(moveOffset))) {
				if (!move.hasGamePiece()) {
					moves.add(move);
				} else if (move.getGamePiece().getPlayer() != this.getPlayer()) {
					moves.add(move);
				}
			}
		}
		return moves;
	}

}
